from fastapi import FastAPI, Request
from sentence_transformers import SentenceTransformer
import uvicorn
import json

app = FastAPI()
model = SentenceTransformer("all-MiniLM-L6-v2")  # 加载模型

@app.post("/embed")
async def get_embeddings(request: Request):
    data = await request.json()
    sentences = data.get("sentences", [])
    embeddings = model.encode(sentences)
    return {"embeddings": embeddings.tolist()}

if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=8000)